<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .bw3{
            width: 100px;
            height: 200px;
            background-color: pink;
        }

        .bw33{
            width: 100px;
            height: 200px;
            background-color: green;
        }
    </style>
</head>

<body>
    <!-- <div id="bw1" aaa="bw2" class="bw3" index="bw3"></div> -->


    <!-- 
        自定义属性的时候：data-*
        *：代表任意字符串
     -->

    <div id="user" data-id="1234567890" data-user="johndoe" data-date-of-birth="20221010" data-date-of-birth1>
            John Doe
          </div>

    <script>
        // const divObj = document.querySelector("div")
        //方式一
        // divObj.className='bw33'

        //方式二
        // divObj.setAttribute("class","bw33")

        const divObj = document.querySelector("div")
        console.log(divObj.dataset)
        console.log(divObj.dataset.id)
        //写法一
        console.log(divObj.dataset.user)
        //写法二
        console.log(divObj.dataset['user'])
        console.log(divObj.dataset.dateOfBirth) //这个是规范
        console.log(divObj.dataset.dateOfBirth1)
        console.log(divObj.dataset.dateOfBirth2)


    </script>
</body>

</html>